package com.tools.service.test.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tools.mapper.test.AnalysisRuleMapper;
import com.tools.pojo.test.AnalysisRule;
import com.tools.service.test.AnalysisRuleService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnalysisRuleServiceImpl extends ServiceImpl<AnalysisRuleMapper, AnalysisRule> implements AnalysisRuleService {

    /**
     * 获取所有启用的规则
     */
    @Override
    public List<AnalysisRule> getEnabledRules() {
        return lambdaQuery()
                .eq(AnalysisRule::getEnabled, 1)
                .orderByAsc(AnalysisRule::getPriority)
                .list();
    }

    /**
     * 根据字段名获取规则
     */
    @Override
    public List<AnalysisRule> getRulesByField(String field) {
        return lambdaQuery()
                .eq(AnalysisRule::getField, field)
                .eq(AnalysisRule::getEnabled, 1)
                .orderByAsc(AnalysisRule::getPriority)
                .list();
    }

    /**
     * 根据多个字段名获取规则
     */
    @Override
    public List<AnalysisRule> getRulesByFields(List<String> fields) {
        return lambdaQuery()
                .in(AnalysisRule::getField, fields)
                .eq(AnalysisRule::getEnabled, 1)
                .orderByAsc(AnalysisRule::getPriority)
                .list();
    }

    /**
     * 根据规则UUID列表获取规则
     */
    @Override
    public List<AnalysisRule> getRulesByUuids(List<String> uuids) {
        if (uuids == null || uuids.isEmpty()) {
            return getEnabledRules();
        }
        return lambdaQuery()
                .in(AnalysisRule::getId, uuids)
                .eq(AnalysisRule::getEnabled, 1)
                .orderByAsc(AnalysisRule::getPriority)
                .list();
    }

}
